/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package layoutlang;

import java.io.File;
import java.io.Serializable;
import java.math.BigInteger;
import java.util.List;
import java.util.ListIterator;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

/**
 *
 * @author rejun001
 */
public class LayoutLangLittle {
    public static void main (String args[]) {
        
        try {
            JAXBContext jc = JAXBContext.newInstance("layoutlang");
            Marshaller m = jc.createMarshaller();
            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
            BigInteger bi_400 = new BigInteger("400");
            
            ObjectFactory oFact = new ObjectFactory();
            EmrRectType eRect = oFact.createEmrRectType();
            eRect.setStacking("top");
            eRect.setHeight("2202790fu");
            eRect.setBackgroundColor("transparent");
            eRect.setBaselineShift("baseline");
            eRect.setBorderBottomColor("transparent");
            eRect.setBorderBottomStyle("none");
            eRect.setBorderBottomWidth("0fu");
            eRect.setBorderTopColor("transparent");
            eRect.setBorderTopStyle("none");
            eRect.setBorderTopWidth("0fu");
            eRect.setContentName("");
            eRect.setFontColor("#000000");
            eRect.setFontDecoration("no-underline");
            eRect.setFontFamily("Arial");
            eRect.setFontSize("1016000fu");
            eRect.setFontStyle("normal");
            eRect.setFontWeight(bi_400);
            eRect.setLayoutError("");
            eRect.setMarginBottom("0fu");
            eRect.setMarginLeft("0fu");
            eRect.setMarginRight("0fu");
            eRect.setMarginTop("0fu");
            eRect.setPaddingBottom("0fu");
            eRect.setPaddingLeft("0fu");
            eRect.setPaddingRight("0fu");
            eRect.setPaddingTop("0fu");
            eRect.setShadingColor("#000000");
            eRect.setShadingHorzOffset("0fu");
            eRect.setShadingSpacing("1219200fu");
            eRect.setShadingVertOffset("0fu");
            eRect.setShadingStyle("clear");
            eRect.setShadingWidth("609600fu");
            eRect.setSpaceBefore("0fu");
            eRect.setSpaceAfter("0fu");
            JAXBElement eRectJXE = oFact.createEmrBandTypeEmrRect(eRect);
            File out = new File("marshall.xml");
            m.marshal(eRectJXE, out);
            
            
            
            
            
            
            
            Unmarshaller um = jc.createUnmarshaller();
            EmrRectType emrRect = (EmrRectType) um.unmarshal(new File("ENCAPSULATED_SFO.xml"));
            String stacking = emrRect.getStacking();
            String height = emrRect.getHeight();
            System.out.println("RECT stacking: " + stacking + ", height: " + height);
            List<Serializable> rectList = emrRect.getContent();
            ListIterator lit = rectList.listIterator();
            while (lit.hasNext()) {
                EmrRectType rect = (EmrRectType) lit.next();
                String backgroundColor = rect.getBackgroundColor();
                String contentName = rect.getContentName();
                System.out.println("\tRECT bg color: " + backgroundColor +
                        ", content name: " + contentName);
            }
            System.out.println("done");
            

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
}
